package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.OrdersItemMapper;
import com.lanyan.system.domain.OrdersItem;
import com.lanyan.system.domain.vo.OrdersItemVo;
import com.lanyan.system.service.IOrdersItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 订单详情Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class OrdersItemServiceImpl  extends ServiceImpl<OrdersItemMapper,OrdersItem> implements IOrdersItemService

{
    @Autowired
    private OrdersItemMapper ordersItemMapper;

    /**
     * 查询订单详情
     *
     * @param ordersItemId 订单详情主键
     * @return 订单详情
     */
    @Override
    public OrdersItem selectOrdersItemByOrdersItemId(Long ordersItemId)
    {
        return this.getById(ordersItemId);
    }

    /**
     * 查询订单详情Vo列表
     *
     * @param ordersItem 订单详情
     * @return 订单详情
     */
    @Override
    public List<OrdersItemVo> selectOrdersItemVoList(OrdersItem ordersItem)
    {
        return selectOrdersItemList(ordersItem)
                .stream()
                .map(x -> (OrdersItemVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询订单详情列表
     *
     * @param ordersItem 订单详情
     * @return 订单详情
     */
    @Override
    public List<OrdersItem> selectOrdersItemList(OrdersItem ordersItem)
    {
        LambdaQueryChainWrapper<OrdersItem> wrapper = this.lambdaQuery().eq(OrdersItem::getDelFlag,"0");
        if (ordersItem.getOrdersId() != null) {
            wrapper.eq(OrdersItem::getOrdersId, ordersItem.getOrdersId());
        }
        if (ordersItem.getProductId() != null) {
            wrapper.eq(OrdersItem::getProductId, ordersItem.getProductId());
        }
        if (ordersItem.getSkuId() != null) {
            wrapper.eq(OrdersItem::getSkuId, ordersItem.getSkuId());
        }
        if (StringUtils.isNotEmpty(ordersItem.getName())) {
            wrapper.like(OrdersItem::getName, ordersItem.getName());
        }
        if (StringUtils.isNotEmpty(ordersItem.getSkuName())) {
            wrapper.like(OrdersItem::getSkuName, ordersItem.getSkuName());
        }
        if (ordersItem.getPrice() != null) {
            wrapper.eq(OrdersItem::getPrice, ordersItem.getPrice());
        }
        if (ordersItem.getNum() != null) {
            wrapper.eq(OrdersItem::getNum, ordersItem.getNum());
        }
        if (StringUtils.isNotEmpty(ordersItem.getIsEvaluate())) {
            wrapper.eq(OrdersItem::getIsEvaluate, ordersItem.getIsEvaluate());
        }
        return wrapper.list();
    }

        /**
         * 新增订单详情
         *
         * @param ordersItem 订单详情
         * @return 结果
         */
    @Override
        public boolean insertOrdersItem(OrdersItem ordersItem)
        {
                    ordersItem.setCreateTime(DateUtils.getNowDate());
                return this.save(ordersItem);
        }

        /**
         * 修改订单详情
         *
         * @param ordersItem 订单详情
         * @return 结果
         */
    @Override
        public boolean updateOrdersItem(OrdersItem ordersItem)
        {
                    ordersItem.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(ordersItem);
        }

        /**
         * 批量删除订单详情
         *
         * @param ordersItemIds 需要删除的订单详情主键
         * @return 结果
         */
    @Override
        public boolean deleteOrdersItemByOrdersItemIds(Long[] ordersItemIds)
        {
            return this.lambdaUpdate().set(OrdersItem::getDelFlag,"1").in(OrdersItem::getOrdersItemId,ordersItemIds).update();
        }

        /**
         * 删除订单详情信息
         *
         * @param ordersItemId 订单详情主键
         * @return 结果
         */
    @Override
        public boolean deleteOrdersItemByOrdersItemId(Long ordersItemId)
        {
            return this.lambdaUpdate().set(OrdersItem::getDelFlag,"1").eq(OrdersItem::getOrdersItemId,ordersItemId).update();
        }
    }
